package com.base;

import java.awt.peer.SystemTrayPeer;

public class Testjoin {
    public  static  void main(String [] args){


        System.out.println(Thread.currentThread().getName()+"主线程启动");
        final Thread thread1= new Thread(new Runnable() {
            public void run() {
                for (int i=0;i<1000;i++)
                {
                    System.out.println("线程——"+ Thread.currentThread().getName());
                }
            }
        });
        thread1.start();

        Thread thread2= new Thread(new Runnable() {
            public void run() {
                try {
                    System.out.println("线程——"+ Thread.currentThread().getName()+"启动");
                    thread1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                for (int i=0;i<1000;i++)
                {
                    System.out.println("线程——"+ Thread.currentThread().getName());
                }
                System.out.println("线程——"+ Thread.currentThread().getName()+"结束");

            }
        });
        thread2.start();
/*        try {
            thread1.join();//加入主线程
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        System.out.println(Thread.currentThread().getName()+"主线程结束");

    }
}
